import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams,AlertController,ToastController} from 'ionic-angular';
import {UserService} from "../../providers/UserService";
import {USERFACE_PATH} from "../../providers/Constants";
import {BaseUI} from "../../common/baseui";
import {UserInfo} from "../../model/UserInfo";

@IonicPage()
@Component({
  selector: 'page-mycontactpersons',
  templateUrl: 'mycontactpersons.html',
})
export class MycontactpersonsPage extends BaseUI{

  userList:any;
  userFacePath:string;
  userId:string;
  constructor(public navCtrl: NavController,
              public navParams: NavParams,
              private userService:UserService,
              private alertCtrl:AlertController,
              private toastCtrl:ToastController) {
    super();
    this.userFacePath = USERFACE_PATH;


  }

  ionViewDidLoad() {
    this.userId = this.navParams.get("userId");
    this.getContactPersonList(this.userId);
  }

  getContactPersonList(userId){
    this.userService.selectContactPerson(userId).subscribe(res=>{
      this.userList = res["data"];
    })
  }

  deleteContactPerson(toUserId){
    let confirm = this.alertCtrl.create({
      message: '是否从最近联系人中移除该用户？',
      buttons: [
        {
          text: '否',
          handler: () => {
          }
        },
        {
          text: '是',
          handler: () => {
            this.userService.deleteContactPerson(this.userId,toUserId).subscribe(res=>{
              super.showToast(this.toastCtrl,res['msg'],'bottom');
              if(res['status']==0){
                this.getContactPersonList(this.userId);
              }
            })
          }
        }
      ]
    });
    confirm.present();
  }

  //聊天
  opneChatDetail(toUserId,toUserPhone,toUserFace,toUserNickName){
    this.navCtrl.push("ChatdetailPage",{chatUserNickName:toUserNickName,
      chatUserFace:toUserFace,
      chatUserPhone:toUserPhone,
      chatUserId:toUserId});
  }

}
